<?php

namespace XWAM\Controller;

/**
 * 敏感词 控制器
 *
 * @since 1.0 <2017-3-24> SoChishun <14507247@qq.com> Added.
 */
class SensitiveWords extends AppbaseController {

    // 2016-4-21
    public function edit() {
        $where = array('title' => 'SensitiveWords-Content', 'conf_group' => 'SensitiveWords');
        $mDict = new \XWAM\Model\SensitiveWordsModel();
        $data = $mDict->where($where)->find();
        if (!$data) {
            $mDict->add($where);
            $data = $mDict->where($where)->find();
        }
        if (!$data) {
            exit('数据库错误!');
        }
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        $this->display();
    }

    // 2017-3-24
    public function user() {
        $where = array('title' => 'SensitiveWords-Name', 'conf_group' => 'SensitiveWords');
        $mDict = new \XWAM\Model\SensitiveWordsModel();
        $data = $mDict->where($where)->find();
        if (!$data) {
            $mDict->add($where);
            $data = $mDict->where($where)->find();
        }
        if (!$data) {
            exit('数据库错误!');
        }
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        $this->display();
    }

    public function editSave() {
        $mDict = new \XWAM\Model\SensitiveWordsModel();
        $result = $mDict->saveConf();
        $this->dialogJump($result['status'], $result['info']);
    }

    // 2017-3-23
    protected function getTabs($name = '') {
        if (!$name) {
            $name = ACTION_NAME;
        }
        $data = array(
            'edit' => array('title' => '内容敏感词', 'url' => 'edit', 'active' => ''),
            'user' => array('title' => '用户名敏感词', 'url' => 'user', 'active' => ''),
        );
        if (array_key_exists($name, $data)) {
            $data[$name]['active'] = 'active';
        }
        return $data;
    }

}
